package com.sike.netty.jinjie.channelPipeline.userevent;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringDecoder;

public class UserEventServer {
    public static void main(String[] args) {
        new ServerBootstrap()
                .group(new NioEventLoopGroup(),new NioEventLoopGroup())
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new StringDecoder());
                        // 先只添加 01 和 02
                        ch.pipeline().addLast("handler01",new DynamicChannelHandler01());
                        ch.pipeline().addLast("handler02",new DynamicChannelHandler02());
                        ch.pipeline().addLast(new CustomerEventHandler());
                    }
                }).bind(8082);
    }
}
